//
// Created by hay boy on 2022/7/19.
//

#ifndef ALGORITHMS_UNITEUSETREE_H
#define ALGORITHMS_UNITEUSETREE_H
int* parent;
void initialize(int numberOfElements){
    parent = new int[numberOfElements+1];
    for(int e = 1;e<=numberOfElements;e++){
        parent[e] = 0;
    }
}
int find(int theElement){
    while(parent[theElement]!=0){
        theElement = parent[theElement];
    }
    return theElement;
}
void unite(int rootA,int rootB){
    parent[rootB] = rootA;
}
#endif //ALGORITHMS_UNITEUSETREE_H
